'\" t
.\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
.\"     <mtk.manpages@gmail.com>
.\"
.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
.TH pthread_kill 3 2022-12-15 "Linux man-pages 6.03"
.SH NAME
pthread_kill \- send a signal to a thread
.SH LIBRARY
POSIX threads library
.RI ( libpthread ", " \-lpthread )
.SH SYNOPSIS
.nf
.B #include <signal.h>
.PP
.BI "int pthread_kill(pthread_t " thread ", int " sig );
.fi
.PP
.RS -4
Feature Test Macro Requirements for glibc (see
.BR feature_test_macros (7)):
.RE
.PP
.BR pthread_kill ():
.nf
    _POSIX_C_SOURCE >= 199506L || _XOPEN_SOURCE >= 500
.fi
.SH DESCRIPTION
The
.BR pthread_kill ()
function sends the signal
.I sig
to
.IR thread ,
a thread in the same process as the caller.
The signal is asynchronously directed to
.IR thread .
.PP
If
.I sig
is 0, then no signal is sent, but error checking is still performed.
.SH RETURN VALUE
On success,
.BR pthread_kill ()
returns 0;
on error, it returns an error number, and no signal is sent.
.SH ERRORS
.TP
.B EINVAL
An invalid signal was specified.
.SH ATTRIBUTES
For an explanation of the terms used in this section, see
.BR attributes (7).
.ad l
.nh
.TS
allbox;
lbx lb lb
l l l.
Interface	Attribute	Value
T{
.BR pthread_kill ()
T}	Thread safety	MT-Safe
.TE
.hy
.ad
.sp 1
.SH STANDARDS
POSIX.1-2001, POSIX.1-2008.
.SH NOTES
Signal dispositions are process-wide:
if a signal handler is installed,
the handler will be invoked in the thread
.IR thread ,
but if the disposition of the signal is "stop", "continue", or "terminate",
this action will affect the whole process.
.PP
The glibc implementation of
.BR pthread_kill ()
gives an error
.RB ( EINVAL )
on attempts to send either of the real-time signals
used internally by the NPTL threading implementation.
See
.BR nptl (7)
for details.
.PP
POSIX.1-2008 recommends that if an implementation detects the use
of a thread ID after the end of its lifetime,
.BR pthread_kill ()
should return the error
.BR ESRCH .
The glibc implementation returns this error in the cases where
an invalid thread ID can be detected.
But note also that POSIX says that an attempt to use a thread ID whose
lifetime has ended produces undefined behavior,
and an attempt to use an invalid thread ID in a call to
.BR pthread_kill ()
can, for example, cause a segmentation fault.
.SH SEE ALSO
.BR kill (2),
.BR sigaction (2),
.BR sigpending (2),
.BR pthread_self (3),
.BR pthread_sigmask (3),
.BR raise (3),
.BR pthreads (7),
.BR signal (7)
